home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 101-125 / scopedisk122 / popup / source / sendmessage.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  2KB  |  73 lines

  1. #include "PopUpMenu.h"
  2.  
  3. /*******************************************************
  4.  * SendMessage(ReplyPort) - Send MENUVERIFY message    *
  5.  *  to all windows on screen with MENUVERIFY flag set. *
  6.  * Input:                           *
  7.  *   ReplyPort - PopUpMenu replyport.               *
  8.  * Output:                           *
  9.  *   return    - Messages sent.                *
  10.  *******************************************************/
  11. SHORT SendMessage(ReplyPort)
  12.   struct MsgPort  *const ReplyPort;
  13. {
  14.   IMPORT struct Window    *const ActiveWindow;
  15.  
  16.   struct Window  *Window;
  17.   WORD     NrOfMessages = 0;
  18.  
  19.   Forbid(); /* To be sure that the windowlist doesn't change */
  20.  
  21.   Window = ActiveWindow->WScreen->FirstWindow;
  22.   do {
  23.     if (Window->IDCMPFlags & MENUVERIFY) {
  24.       struct IntuiMessage *const Message =
  25.               BuildIntuiMsg(ReplyPort, MENUVERIFY,
  26.                  (Window == ActiveWindow) ? MENUHOT : MENUWAITING);
  27.       if (Message) {
  28.     CurrentTime(&Message->Seconds,&Message->Micros);
  29.     Message->IDCMPWindow = Window;
  30.  
  31.     PutMsg(Window->UserPort,(struct Message *)Message);
  32.     NrOfMessages++;
  33.       }
  34.     }
  35.   }
  36.   while (Window = Window->NextWindow);
  37.  
  38.   Permit();
  39.  
  40.   return (NrOfMessages);
  41. }
  42.  
  43. /***************************************
  44.  * BuildIntuiMsg(ReplyMsg,Class,Code)  *
  45.  *                       *
  46.  * Input:                   *
  47.  *   ReplyPort                   *
  48.  *   Class                   *
  49.  *   Code                   *
  50.  * Output:                   *
  51.  *   return    -  IntuiMessage           *
  52.  ***************************************/
  53. struct IntuiMessage *BuildIntuiMsg(ReplyPort,Class,Code)
  54.   struct MsgPort  *const ReplyPort;
  55.   ULONG   Class;
  56.   UWORD   Code;
  57. {
  58.   struct IntuiMessage *const Message =
  59.         AllocMem(sizeof(struct IntuiMessage),MEMF_PUBLIC | MEMF_CLEAR);
  60.  
  61.   if (Message) {
  62.     Message->ExecMessage.mn_Node.ln_Type = NT_MESSAGE;
  63.     Message->ExecMessage.mn_ReplyPort     = ReplyPort;
  64.     Message->ExecMessage.mn_Length     = sizeof(struct IntuiMessage) -
  65.                        sizeof(struct Message);
  66.     Message->Class = Class;
  67.     Message->Code  = Code;
  68.   }
  69.   return (Message);
  70. }
  71.  
  72.  
  73.